const findChildren = require('./findChildren')
const treeData = require('./treeData')

const defaultItemPropMap = {
  keyProp: 'value',
  childrenProp: 'children',
  deepdashOptions: {
    childrenPath: ['children']
  }
}

function hasChildren(
  treeData,
  ancestor,
  child,
  propMap = defaultItemPropMap
) {
  const allChildren = findChildren(treeData, ancestor, propMap)
  const searchValue = child[propMap.keyProp]
  return allChildren.some(item => item[propMap.keyProp] === searchValue)
}

module.exports = hasChildren


const ancestor = {
  value: 40
}
const child = {
  value: 544
}
const hasIt = hasChildren(treeData, ancestor, child, defaultItemPropMap)
console.log(`ancestor ${ancestor.value} has child ${child.value} is: `, hasIt)
